﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UClaimDemageListAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "UClaimDemageList"; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }
        private void addmenu()
        {
            UClaimDemageInfo obj = Request.SerializableObject<UClaimDemageInfo>();
           // obj.AgentName = GetRequestValue<string>("dwz_orgLookup.AgentName", "");
           // obj.ItemCode = GetRequestValue<string>("dwz_orgLookup.ItemCode", "");
            //obj.Dscription = GetRequestValue<string>("dwz_orgLookup.ItemName", "");

            if (obj.Price <= 0 && obj.UClaimType == "借件")
            {
                string tempPrice = SBOController.GetOITMLastPurPrice(obj.ItemCode);
                obj.Price = Convert.ToDecimal(tempPrice);
            }
            else
                obj.Price = 0;

            obj.InStock = base.User.IsSuperAdmin ? GetRequestValue<bool>("InStock", true) : true;            
            obj.U_OutTypeText = obj.U_OutType == "54010301" ? "索赔出库" : obj.U_OutType == "55011900" ? "保养件出库" : "其它";
            obj.LineTotal = obj.Price * obj.Quantity;
            obj.DocEntry = 0;
            obj.LineTotal = 0m;

            AddLog(Permission.新增, obj);
            // obj.UserName = GetRequestValue<string>("dwz_orgLookup.UserName", "");
            int r = UClaimDemageController.Add(obj);
            if (r > 0)
                SuccessJson("添加成功", this.DWZRef);
            else
            {
                ErrorJson("添加失败", this.DWZRef);
            }
        }
    }
}